package org.beian.fmmall.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.beian.fmmall.VO.ResultVO;
import org.beian.fmmall.service.ProductCommentsService;
import org.beian.fmmall.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/product")
@Api(tags = "商品管理",value = "提供商品信息相关的接口")
public class ProductController {
    @Autowired
    private ProductService productService;
    @Autowired
    private ProductCommentsService productCommentsService;

    @GetMapping("/basic-info/{pid}")
    @ApiOperation("商品基本信息查询接口")
    public ResultVO getProductBasicInfo(@PathVariable("pid") String pid){
        return productService.getProductBasicInfo(pid);
    }

    @GetMapping("/detail-info/{pid}")
    @ApiOperation("商品详情信息查询接口")
    public ResultVO getProductDetailInfo(@PathVariable("pid") String pid){
        return productService.getProductParamsById(pid);
    }

    @GetMapping("/detail-comments/{pid}")
    @ApiOperation("商品评论信息查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value ="当前页码数",required = true ),
            @ApiImplicitParam(name = "limit",value ="每页显示条数",required = true )
    })
    public ResultVO getProductComments(@PathVariable("pid") String pid,int pageNum,int limit){
        return productCommentsService.listCommentsByProductId(pid,pageNum,limit);
    }

    @GetMapping("/detail-commentscount/{pid}")
    @ApiOperation("商品评论统计查询接口")
    public ResultVO getProductCommentsCount(@PathVariable("pid") String pid){
        return productCommentsService.getCommentsCountByProductId(pid);
    }
    @ApiOperation("根据类别查询商品接口")
    @GetMapping("/listByCid/{cid}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码"),
            @ApiImplicitParam(name = "limit",value = "每页显示条数")
    })
    public ResultVO getProductsByCategory(@PathVariable("cid") int cid,int pageNum,int limit){
        return productService.getProductByCategoryId(cid, pageNum, limit);
    }
    @ApiOperation("根据类别查询商品品牌")
    @GetMapping("/listBrands/{cid}")
    public ResultVO getBrandByCategory(@PathVariable("cid") int cid){
        return productService.getBrandByCategoryId(cid);
    }
    @ApiOperation("根据关键词查询商品品牌")
    @GetMapping("/listBrandsBySearch")
    public ResultVO getBrandBySearch(String keyWord){
        return productService.getBrandBySearch(keyWord);
    }

    @ApiOperation("根据品牌查询商品接口")
    @GetMapping("/listByBrandByCid/{cid}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码"),
            @ApiImplicitParam(name = "limit",value = "每页显示条数"),
            @ApiImplicitParam(name = "brand",value = "品牌")
    })
    public ResultVO getProductByBrand(@PathVariable("cid") int cid,int pageNum,int limit,String brand){
        return productService.getProductsByBrand(cid, pageNum, limit, brand);
    }

    @ApiOperation("根据搜索关键词查询商品接口")
    @GetMapping("/listBySearch")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码"),
            @ApiImplicitParam(name = "limit",value = "每页显示条数"),
            @ApiImplicitParam(name = "keyWord",value = "搜索关键词")
    })
    public ResultVO getProductsByCategory(int pageNum,int limit,String keyWord){
        return productService.getProductsBySearch(pageNum, limit, keyWord);
    }
}
